package com.bioscript.standalone.dataStructures;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

public class Generation {
	
	private Map<String,Object> map = new HashMap<String, Object>();
	public enum types
	{
		DeNovo,
		Mapped;
	}

	enum Props
	{
		name,
		type;
	}
	
	public Generation(String name, String type)
	{
		super();
		map.put(Props.name.toString(), name);
		map.put(Props.type.toString(), type);
	}
	
	public String getName()
	{
		return (String)map.get(Props.name.toString());
	}
	
	public String getType()
	{
		return (String)map.get(Props.type.toString());
	}
	
	public static List<Generation> getGenerations(NodeList ndList)
	{
		List<Generation> result = new ArrayList<Generation>();
		int length = ndList.getLength();
		for (int i = 0; i < length ; i++)
		{
			Element el = (Element) ndList.item(i);
			Generation gen = Generation.newInstance(el);
			result.add(gen);
		}
		return result;
	}

	private static Generation newInstance(Element el) {
		return new Generation(el.getAttribute(Props.name.toString()),
				el.getAttribute(Props.type.toString()));
	}

	public boolean toXML(Document doc, Element el) {
		Element gen = doc.createElement("gen");
		gen.setAttribute(Props.name.toString(), (String)getName());
		gen.setAttribute(Props.type.toString(), (String)getType());
		el.appendChild(gen);
		return true;
	}
}
